import {
	fetchList,
	leftreact,
	depositList,
	particulars,
	search,
	listParticulars,
	MobilePhoneLogin,
	ShoppingCartList,
	ShoppingAdd,
	ShoppingDelete
} from "@/api/index.js"

const state = {
	fetchList: '', //轮播图
	leftreact: '', //新品上市
	depositList: '', //为您推存
	particulars: '', //详情
	search: '', //搜索name
	listParticulars: '', //列表详情
	MobilePhoneLogin: '', //手机号登录
	ShoppingCartList: '', //购物车列表
	ShoppingAdd: '', //add
	ShoppingDelete: '', //delete
}

const mutations = {
	// 轮播图
	SET_VUEXTEXT: (state, data) => {
		state.fetchList = data
	},
	// 新品上市
	SET_LEFTREACT: (state, data) => {
		state.leftreact = data
	},
	// 为您推存
	SET_DEPOSIT: (state, data) => {
		state.depositList = data
	},
	// 详情
	SET_part: (state, data) => {
		state.particulars = data
	},
	// 搜索name
	SET_search: (state, data) => {
		state.search = data
	},
	// 列表详情
	SET_listParticulars: (state, data) => {
		state.listParticulars = data
	},
	// 手机号登录
	SET_MobilePhoneLogin: (state, data) => {
		state.MobilePhoneLogin = data
	},
	// 购物车列表
	SET_ShoppingCartList: (state, data) => {
		state.ShoppingCartList = data
	},
	// add
	SET_ShoppingAdd: (state, data) => {
		state.ShoppingAdd = data
	},
	// delete
	SET_ShoppingDelete: (state, data) => {
		state.ShoppingDelete = data
	},
}

const actions = {
	// 测试调用api接口使用
	// 轮播图
	vuexTest({
		commit
	}, data) {
		// console.log(data,1212)
		// return bar()
		return new Promise((resolve, reject) => {
			let testState = fetchList()
			if (testState) {
				commit("SET_VUEXTEXT", testState + data)
				resolve(testState)
			} else {
				reject('失败')
			}
		})
	},
	// 新品上市
	vuexLeft({
		commit
	}, data) {
		// console.log(data,1212)
		// return bar()
		return new Promise((resolve, reject) => {
			let leftreacts = leftreact()
			if (leftreacts) {
				commit("SET_LEFTREACT", leftreacts + data)
				resolve(leftreacts)
			} else {
				reject('失败')
			}
		})
	},
	// 为您推存
	vuexdeposit({
		commit
	}, data) {
		return new Promise((resolve, reject) => {
			let testState = depositList(data)
			// console.log(data,'89098')
			if (testState) {
				commit("SET_DEPOSIT", testState + data)
				resolve(testState)
			} else {
				reject('失败')
			}
		})
	},
	// 详情
	vuexparticulars({
		commit
	}, data) {
		return new Promise((resolve, reject) => {
			let testState = particulars(data)
			if (testState) {
				commit("SET_part", testState + data)
				resolve(testState)
			} else {
				reject('失败')
			}
		})
	},
	// 搜索name
	vuexsearchName({
		commit
	}, data) {
		return new Promise((resolve, reject) => {
			let testState = search(data)
			if (testState) {
				commit("SET_search", testState + data)
				resolve(testState)
			} else {
				reject('失败')
			}
		})
	},
	// 列表详情
	vuexlistParticulars({
		commit
	}, data) {
		return new Promise((resolve, reject) => {
			let testState = listParticulars(data)
			if (testState) {
				commit("SET_listParticulars", testState + data)
				resolve(testState)
			} else {
				reject('失败')
			}
		})
	},
	// 输入手机号登录  
	vuexMobilePhoneLogin({
		commit
	}, data) {
		return new Promise((resolve, reject) => {
			let testState = MobilePhoneLogin(data)
			if (testState) {
				commit("SET_MobilePhoneLogin", testState + data)
				resolve(testState)
			} else {
				reject('失败')
			}
		})
	},
	// 购物车列表
	vuexShoppingCartList({
		commit
	}, data) {
		return new Promise((resolve, reject) => {
			let testState = ShoppingCartList(data)
			if (testState) {
				commit("SET_ShoppingCartList", testState + data)
				resolve(testState)
			} else {
				reject('失败')
			}
		})
	},
	// add购物车
	vuexShoppingAdd({
		commit
	}, data) {
		return new Promise((resolve, reject) => {
			let testState = ShoppingAdd(data)
			console.log(testState, 'data12')
			if (testState) {
				commit("SET_ShoppingAdd", testState + data)
				resolve(testState)
			} else {
				reject('失败')
			}
		})
	},
	// delete
	VuexShoppingDelete({
		commit
	}, data) {
		return new Promise((resolve, reject) => {
			let testState = ShoppingDelete(data)
			console.log(data)
			if (testState) {
				commit("SET_ShoppingDelete", testState + data)
				resolve(testState)
			} else {
				reject('失败')
			}
		})
	}
}



export default {
	namespaced: true,
	state,
	mutations,
	actions
}
